package com.reremouse.rerebbs.web.mb;

import com.reremouse.rerebbs.dao.IBbsMessageDAO;
import com.reremouse.rerebbs.dao.IBbsUserDAO;
import com.reremouse.rerebbs.model.BbsMessage;
import com.reremouse.rerebbs.model.BbsUser;
import com.reremouse.util.JsfHelper;
import com.reremouse.util.SpringHelper;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

@ManagedBean
@ViewScoped
public class ClientSendMsg
        implements Serializable {
    IBbsMessageDAO messageDAO = (IBbsMessageDAO) SpringHelper.getSpringBean("BbsMessageDAO");
    IBbsUserDAO clientUserDAO = (IBbsUserDAO) SpringHelper.getSpringBean("BbsUserDAO");
    ClientSession cs = (ClientSession) JsfHelper.getBean("clientSession");
    BbsMessage mm = new BbsMessage();
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    boolean ifSendEmail;
    boolean ifSendOK = false;

    public boolean isIfSendOK() {
        return this.ifSendOK;
    }

    public void setIfSendOK(boolean ifSendOK) {
        this.ifSendOK = ifSendOK;
    }

    public boolean isIfSendEmail() {
        return this.ifSendEmail;
    }

    public void setIfSendEmail(boolean ifSendEmail) {
        this.ifSendEmail = ifSendEmail;
    }

    public BbsMessage getMm() {
        return this.mm;
    }

    public void setMm(BbsMessage mm) {
        this.mm = mm;
    }

    @PostConstruct
    public void init() {
        String idt = this.request.getParameter("uid");
        if (idt != null) {
            BbsUser bu = this.clientUserDAO.findBbsUser(Long.parseLong(idt));
            if (bu != null) {
                this.mm.setReceiver(this.clientUserDAO.findBbsUser(Long.parseLong(idt)));
            }
            if (this.cs == null) {
                return;
            }
            BbsUser cu = this.cs.getUsr();
            if (cu != null) {
                this.mm.setSender(cu);
            }
        }
    }

    public String send() {
        this.messageDAO.addMessageModel(this.mm);
        this.ifSendOK = true;
        return "ClientSendMsgSuccess";
    }

    public void begainSend(long to) {
        this.mm = new BbsMessage();
        BbsUser bu = this.clientUserDAO.findBbsUser(to);
        if (bu != null) {
            this.mm.setReceiver(bu);
        }
        BbsUser cu = this.cs.getUsr();
        if (cu != null) {
            this.mm.setSender(cu);
        }
    }

    /* :0:   */
    public void sendOK()
/* :1:   */ {
/* :2:90 */
        this.messageDAO.addMessageModel(this.mm);
/* :3:91 */
        this.ifSendOK = true;
/* :4:   */
    }
/* :5:   */
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.ClientSendMsg

 * JD-Core Version:    0.7.0.1

 */